#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <queue>
#include <map>
using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, string> PIS;
queue<PIS> Q; 
map<string, bool> vis;
int res = 0;
string swap(string s, int i, int j)
{
    char temp = s[i];
    s[i] = s[j];
    s[j] = temp;
    return s;
}
int bfs(int pos, int n, string Startsit, string Endsit)
{
    Q.push({{pos, 0} ,Startsit});
    vis.insert({Startsit, true});
    while (!Q.empty())
    {
        PIS now = Q.front();
        Q.pop();
        if (now.second == Endsit)
        {
            return now.first.second;
        }
        for (int i = now.first.first - 3; i <= now.first.first + 3; i++)
        {
            if(i < 0 || i >= n || i == now.first.first)continue;
            string after = swap(now.second, now.first.first, i);
            if (vis.find(after) != vis.end())continue;
            vis.insert({after, true});
            Q.push({{i, now.first.second + 1}, after});
        }
    }
    return -1;
}
int main()
{
    string Startsit, Endsit;
    cin >> Startsit >> Endsit;
    int pos;
    int n = Startsit.size();
    for (int i = 0; i < n; i++)
        if (Startsit[i] == '*')
        {
            pos = i;
            break;
        }
    
    res = bfs(pos, n, Startsit, Endsit);
    printf("%d\n", res);
    return 0;
}